package baza.games.airSoccer;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Ball implements IDrawableComponent, Cloneable {

	private float initialX;
	private float initialY;
	
	public float posX=0;
	public float posY=0;
	public float radio=25;
	public float vx=0;
	public float vy=0;
	private AirSoccerEngine currEngine;
	
	public Ball()
	{
		 posX = AirSoccerEngine.netWidth/2;
		 posY = AirSoccerEngine.netHeight/2;
		 this.initialX = posX;
		 this.initialY = posY;
		 
	}
	
	public void draw(Canvas canvas) {
		Paint paint = new Paint();
		paint.setColor(Color.WHITE);
		canvas.drawCircle(posX, posY, radio, paint);
		
	}
	
	public void center()
	{
		this.vx =0;
		this.vy =0;
		this.posX = initialX;
		this.posY = initialY;
	}

	public void update() 
	{
		
		posX += vx;
		posY += vy;
			vx = vx*(1-AirSoccerEngine.atrito);
			vy = vy*(1-AirSoccerEngine.atrito);
			
			//Colisao com as paredes
			if((posX+radio >= AirSoccerEngine.netWidth) ||
					posX-radio <= 0)
				vx *= -1;
			
			if((posY+radio >= AirSoccerEngine.netHeight) ||
					posY-radio <= 0)
				vy *= -1;
			
		
		currEngine.colocaBolaPosicaoValida();
		
	}
	
	public float getMass()
	{
		return radio/2;
	}

	public void setEngine(AirSoccerEngine engine) {
		this.currEngine = engine;
		
	}

	public Object clone()
	{
		Ball b = new Ball();
		b.posX=this.posX;
		b.posY=this.posY;
		b.radio=this.radio;
		b.vx=this.vx;
		b.vy=this.vy;
		
		
		return b;
	}
	
}
